package edu.pku.taas.hyperic.types2;

public class AppdefTypeTransferUtil {
	// from AppdefEntityConstants
	public static final int APPDEF_TYPE_PLATFORM = 1;
	public static final int APPDEF_TYPE_SERVER = 2;
	public static final int APPDEF_TYPE_SERVICE = 3;
	public static final int APPDEF_TYPE_APPLICATION = 4;
	public static final int APPDEF_TYPE_GROUP = 5;
	public static final int APPDEF_TYPE_AIPLATFORM = 6;
	public static final int APPDEF_TYPE_AISERVER = 7;
	public static final int APPDEF_TYPE_AIIP = 8;
	public static final int APPDEF_TYPE_AUTOGROUP = 9;

	// from AuthzConstants
	public static final int authzSubject = 1;
	public static final int authzRole = 2;
	public static final int authzGroup = 3;
	public static final int authzPlatform = 301;
	public static final int authzServer = 303;
	public static final int authzService = 305;
	public static final int authzApplication = 308;
	public static final int authzEscalation = 401;
	public static final int authzHQSystem = 501;
	public static final int authzLocation = 309;
	public static final int authzPlatformProto = 601;
	public static final int authzServerProto = 602;
	public static final int authzServiceProto = 603;
	public static final int authzApplicationProto = 604;
	
	
//	PLATFORM = 1 -- 301 ;
//	SERVER = 2  -- 303;
//	SERVICE = 3 -- 305;
//	APPLICATION = 4 -- 308;
//	GROUP = 5 -- 3;

	// public static final Integer authzSubject = new Integer(1);
	// public static final Integer authzRole = new Integer(2);
	// public static final Integer authzGroup = new Integer(3);
	// public static final Integer authzPlatform = new Integer(301);
	// public static final Integer authzServer = new Integer(303);
	// public static final Integer authzService = new Integer(305);
	// public static final Integer authzApplication = new Integer(308);
	// public static final Integer authzEscalation = new Integer(401);
	// public static final Integer authzHQSystem = new Integer(501);
	// public static final Integer authzLocation = new Integer(309);
	// public static final Integer authzPlatformProto = new Integer(601);
	// public static final Integer authzServerProto = new Integer(602);
	// public static final Integer authzServiceProto = new Integer(603);
	// public static final Integer authzApplicationProto = new Integer(604);

	public static int transferAppdefType2RawType(int appType) {
		int _entityType;

		switch (appType) {
		case authzPlatform:
			_entityType = APPDEF_TYPE_PLATFORM;
			break;
		case authzServer:
			_entityType = APPDEF_TYPE_SERVER;
			break;
		case authzService:
			_entityType = APPDEF_TYPE_SERVICE;
			break;
		case authzApplication:
			_entityType = APPDEF_TYPE_APPLICATION;
			break;
		case authzGroup:
			_entityType = APPDEF_TYPE_GROUP;
			break;
		default:
			System.out.println("Error:"+appType
					+ " is not a valid Appdef Resource Type");
			throw new IllegalArgumentException(appType
					+ " is not a valid Appdef Resource Type");

		}
		return _entityType;
	}
	
	public static int transferRawType2AppdefType(int rawType) {
		int _entityType;

		switch (rawType) {
		case APPDEF_TYPE_PLATFORM:
			_entityType = authzPlatform;
			break;
		case APPDEF_TYPE_SERVER:
			_entityType = authzServer;
			break;
		case APPDEF_TYPE_SERVICE:
			_entityType = authzService;
			break;
		case APPDEF_TYPE_APPLICATION:
			_entityType = authzApplication;
			break;
		case APPDEF_TYPE_GROUP:
			_entityType = authzGroup;
			break;
		default:
			System.out.println("Error:"+rawType
					+ " is not a valid Resource Type");
			throw new IllegalArgumentException(rawType
					+ " is not a valid Resource Type");

		}
		return _entityType;
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
//		PLATFORM = 1 -- 301 ;
//		SERVER = 2  -- 303;
//		SERVICE = 3 -- 305;
//		APPLICATION = 4 -- 308;
//		GROUP = 5 -- 3;
		System.out.println("transferRawType2AppdefType:");
		System.out.println(transferRawType2AppdefType(1));
		System.out.println(transferRawType2AppdefType(2));
		System.out.println(transferRawType2AppdefType(3));
		System.out.println(transferRawType2AppdefType(4));
		System.out.println(transferRawType2AppdefType(5));
		
		System.out.println("transferAppdefType2RawType:");
		System.out.println(transferAppdefType2RawType(3));
		System.out.println(transferAppdefType2RawType(301));
		System.out.println(transferAppdefType2RawType(303));
		System.out.println(transferAppdefType2RawType(305));
		System.out.println(transferAppdefType2RawType(308));
	}

}
